// endPointStr格式未lng,lat;lng,lat:....
function createPointGeoJson(pointStr){
    let pointsCollection = {
        type: 'FeatureCollection',
        features: []
    }
    let tempStrArr = pointStr.split(',');
    for(let i=0;i<tempStrArr.length;){
        let pointJson = {
            type: 'Feature',
            geometry: {
                type: 'Point',
                coordinates: []//coordinates
            }
        };
        let tmpPoint = [tempStrArr[i], tempStrArr[i+1]];
        //线的geojson
        pointJson.geometry.coordinates.push(tmpPoint);
        pointsCollection.features.push(pointJson);
        i=i+2;
    }
    return pointsCollection;

}
function createLineGeoJson(lineStr) {
    let lineJson = {
        type: 'Feature',
        properties: {},
        geometry: {
            type: 'LineString',
            coordinates: []//coordinates
        }
    };
    let tempStrArr = lineStr.split(',');
   for (let i=0;i<tempStrArr.length;){
       let tmpPoint = [tempStrArr[i], tempStrArr[i+1]];
       //线的geojson
       lineJson.geometry.coordinates.push(tmpPoint);
       i=i+2;
   }
    return lineJson;
}

function createPolygonGeoJson(polyStr) {
    let polyJson = {
        type: 'Feature',
        properties: {},
        geometry: {
            type: 'Polygon',
            coordinates: []//coordinates
        }
    };
    let tempStrArr = polyStr.split(',');
    for (let i=0;i<tempStrArr.length;){
        let tmpPoint = [tempStrArr[i], tempStrArr[i+1]];
        //线的geojson
        polyJson.geometry.coordinates.push(tmpPoint);
        i=i+2;
    }
    return polyJson;
}
function addFeatureToMap(map,geojson) {
    map.addSource('lineSource', {
        'type': 'geojson',
        'data': geojson
    });
    map.addLayer({
        id: 'route1',
        type: 'line',
        source: 'lineSource',
        layout: {},
        paint: {
            'line-color': '#31881e',
            'line-width': 2
        }
    });
}
function addMapService(map,wmsUrl) {
    map.addSource('wms-source',{
        type:'raster',
        tiles:[wmsUrl]
    });
    map.addLayer({
        'id':'wms-vector',
        'type':'raster',
        'source':'wms-source',
        'source-layer':'njmap_group_darkstyle',

    });
}
export {createPointGeoJson,createLineGeoJson,createPolygonGeoJson,addMapService}